﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Checkers.Common
{
    /// <summary>
    /// This class represent a location 
    /// </summary>
    public class Location
    {
        // Data members
        private int m_Row;
        private int m_Col;

        // Properties
        
        /// <summary>
        /// Getter to m_Row
        /// </summary>
        public int Row
        {
            get
            {
                return m_Row;
            }
        }

        /// <summary>
        /// Getter to m_Col
        /// </summary>
        public int Column
        {
            get
            {
                return m_Col;
            }
        }   

        // Ctors
        // Empty Ctor
	    public Location()
	    {
            m_Row = 0;
            m_Col = 0;
	    }

	    // Ctor that init the data members
        public Location(int i_Row, int i_Col)
        {
            m_Row = i_Row;
            m_Col = i_Col;
        }

        // Ctor that init the data members
        public Location(Location i_location)
        {
            m_Row = i_location.Row;
            m_Col = i_location.Column;
        }

	    // Ctor that init the data members according to location with letter and number (like 'A5')
        public Location(string i_StringLocation)
        {
            // Parse the location from string to location
            parseLocation(i_StringLocation);
        }

        // Private methods

        /// <summary>
        /// Parse the location from string to location
        /// </summary>
        /// <param name="i_StringLocation">The input string from the user</param>
        private void parseLocation(string i_StringLocation)
        {
            // Variabls
            char cLetter = i_StringLocation[0];
            char cNum = i_StringLocation[1];

            // Set the values of the row and column
            m_Col = (int)(char.ToUpper(cLetter) - GameBoard.k_BoardStartColumn + 1);
            m_Row = (int)(cNum - '1' + 1);
        }

        /// <summary>
        /// Converts a Location object into a string
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0}{1}", (char)(m_Col + GameBoard.k_BoardStartColumn - 1), m_Row);
        }
    }
}
